import { CoolController, BaseController } from '@cool-midway/core';
import { GoodsPromoMjEntity } from '../../entity/promo_mj';
import { GoodsPromoMjService } from '../../service/promo_mj.service';
import { Body, Inject, Post } from '@midwayjs/core';

/**
 * 促销满减管理
 */
@CoolController({
  api: ['page', 'info'],
  entity: GoodsPromoMjEntity,
  service: GoodsPromoMjService,
  pageQueryOp: {
    fieldEq: ['a.status', 'a.billNo'],
    addOrderBy: {
      createTime: 'desc',
    },
  },
})
export class AdminGoodsPromoMjController extends BaseController {
  @Inject()
  goodsPromoMjService: GoodsPromoMjService;

  @Post('/getByBillNo')
  async getByBillNo(@Body() params: { billNo: string }) {
    return this.ok(await this.goodsPromoMjService.getByBillNo(params.billNo));
  }

  @Post('/getAllActiveDetails')
  async getAllActiveDetails() {
    return this.ok(await this.goodsPromoMjService.getAllActiveDetails());
  }

  @Post('/calculateDiscount')
  async calculateDiscount(@Body() params: { billNo: string; totalAmount: number }) {
    return this.ok(await this.goodsPromoMjService.calculateDiscount(params.billNo, params.totalAmount));
  }

  @Post('/getDiscountConditions')
  async getDiscountConditions(@Body() params: { billNo: string }) {
    return this.ok(await this.goodsPromoMjService.getDiscountConditions(params.billNo));
  }
} 